﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.ComponentModel;

namespace Dotway.WPF.Controls.Utilities
{
    /// <summary>
    /// Color representation in r,g,b with values [0.0 - 1.0].
    /// </summary>
    public struct RGB
    {
        public RGB(Color color)
        {
            r = 0.0;
            g = 0.0;
            b = 0.0;

            R = color.R / 255.0;
            G = color.G / 255.0;
            B = color.B / 255.0;
        }

        /// <summary>
        /// Each value must be in the span 0 - 255.
        /// </summary>
        /// <param name="red"></param>
        /// <param name="green"></param>
        /// <param name="blue"></param>
        public RGB(byte red, byte green, byte blue)
        {
            r = 0.0;
            g = 0.0;
            b = 0.0;

            R = red / 255.0;
            G = green / 255.0;
            B = blue / 255.0;
        }

        /// <summary>
        /// Each value must be in the span 0.0 - 1.0.
        /// </summary>
        /// <param name="red"></param>
        /// <param name="green"></param>
        /// <param name="blue"></param>
        public RGB(double red, double green, double blue)
        {
            r = 0.0;
            g = 0.0;
            b = 0.0;

            R = red;
            G = green;
            B = blue;
        }        

        private double r;
        public double R
        {
            get { return r; }
            set
            {
                if (value >= 0.0 && value <= 1.0)
                {
                    r = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("R is not in the span [0, 1]");
                }
            }
        }

        private double g;
        public double G
        {
            get { return g; }
            set
            {
                if (value >= 0.0 && value <= 1.0)
                {
                    g = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("G is not in the span [0, 1]");
                }
            }
        }

        private double b;
        public double B
        {
            get { return b; }
            set
            {
                if (value >= 0.0 && value <= 1.0)
                {
                    b = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("B is not in the span [0, 1]");
                }
            }
        }
    }
}
